package javabase.biji;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * @Auther: luzhanshi
 * @Date: 2021/2/2 - 02 - 02 - 13:54 
 * @Description: javabase.biji
 * @version: 1.0
 */
public class _28List {


    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("1");
        list.add("2");
        list.add("3");
        ListIterator listIterator = list.listIterator();
        while (listIterator.hasNext()) {
            System.out.println(listIterator.next());
        }
        System.out.println("------------");

        while (listIterator.hasPrevious()) {//listIterator.next()不执行的话，listIterator.hasPrevious()是false
            System.out.println(listIterator.previous());
        }
        System.out.println("------------");
        listIterator.add("4");//由于listIterator.previous()已经将指针移动到list最前方，所以“4”被添加到第一个
        System.out.println(list);
        list.add("5");//普通add方法追加元素在末尾
        for (Object o : list) {//iter快速生成增强for循环
            System.out.println(o);
        }


        System.out.println("-----------------------");
        System.out.println(list.get(3));
        System.out.println(list);
        list.add(3,"33");
        System.out.println("-----------------------");
        System.out.println(list.get(3));
        System.out.println(list);
    }
}
